package com.niit.service.impl;

import java.util.List;

import com.niit.bean.Job;
import com.niit.dao.JobDao;
import com.niit.dao.impl.JobDaoImpl;
import com.niit.service.JobService;
import com.niit.utils.Page;

public class JobServiceImpl implements JobService {
	
	private JobDao dao = new JobDaoImpl();
	@Override
	public int add(Job t) {
		return dao.add(t);
	}

	@Override
	public int delete(Job t) {
		return dao.delete(t);
	}

	@Override
	public int update(Job t) {
		return dao.delete(t);
	}

	@Override
	public Job findById(String id) {
		
		return dao.findById(id);
	}

	@Override
	public Page<Job> getPage(String pagenum, String url) {
		int total = dao.findTotal();//查出总记录数
		Page<Job> page = null;
		if(pagenum == null){
			page = new Page<Job>(total,1);
		}else{
			page = new Page<Job>(total, Integer.parseInt(pagenum));
		}
		List<Job> list = dao.findAll(page.getStartIndex(), page.getEndIndex());
		page.setList(list);
		page.setUrl(url);
		return page;
	}


	public Page<Job> getPage(String pagenum, String url, int type, String val) {
		int total = dao.findTotal();// 查出总记录数
		Page<Job> page = null;
		if (pagenum == null) {
			page = new Page<Job>(total, 1);
		} else {
			page = new Page<Job>(total, Integer.parseInt(pagenum));
		}
		if (type == 0) { // type =0 查询学历
			String education = null;
			if (val.equals("0")) {
				education = "不限";
//				education = "*";
			} else if (val.equals("1")) {
				education = "大专";
			} else if (val.equals("2")) {
				education = "本科";
			} else if (val.equals("3")) {
				education = "研究生";
			}
			List<Job> list = dao.findByEdu(education, page.getStartIndex(),
					page.getEndIndex());
			page.setList(list);
			page.setUrl(url);
			return page;
		} else if (type == 1) { // type =1 查询工作经验
//			if (val=="0"){
//				val = "*";
//			}
			List<Job> list = dao.findByExp(val, page.getStartIndex(), page.getEndIndex());
			page.setList(list);
			page.setUrl(url);
			return page;
		}else{			
			return null;
		}
	}
}
